package com.lut.edu.apm.webCenter.controller;

import com.alibaba.fastjson.JSONObject;
import com.lut.edu.apm.webCenter.pojo.UserInfo;
import com.lut.edu.apm.webCenter.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Zhao Suzhen
 * @date `2024/5/22`
 */
@RestController
@RequestMapping("/user")
public class UserInfoConteroller {

    @Autowired
    UserInfoService userInfoService;

    @GetMapping("queryIntegral")
    @ResponseBody
    public String queryIntegral(@RequestParam("phoneNumber") String phoneNumber) {
        UserInfo userInfo = userInfoService.queryInfoByPhone(phoneNumber);
        Map<String, Object> result = new HashMap<>();
        if (null != userInfo) {
            result.put("isSuccess", 200);
            result.put("integral", userInfo.getUserPoints());
        } else {
            result.put("isSuccess", 401);
            result.put("error", "用户信息为空");
        }
        return JSONObject.toJSONString(result);
    }

    @GetMapping("/updateSex")
    @ResponseBody
    public String updateSex(@RequestParam("userId") String userId, @RequestParam String sex) {
        Map<String, Object> result = new HashMap<>();
        userInfoService.updateUserSex(userId, sex);
        result.put("isSuccess", 200);
        return JSONObject.toJSONString(result);
    }
}
